<?
#####################################################
#  COPYRIGHT NOTICE
#####################################################
# In the following statements, the term "this 
# program" refers to all files associated with the
# execution and distribution of Adtrackz.
#
# This Program is Copyright 2004 Jonah Klimack.
# All Rights Reserved. 
#
# Selling the code for this program, modifying 
# and/or redistributing the code for this program
# in part or in whole over the Internet or in any 
# other medium is expressly forbidden. Violators
# will be prosecuted to the fullest extent of the law
# Copyright and header information may not be
# modified.
#
# This program is distributed "as is" and without 
# warranty of any kind, either express or implied.
# In no event shall the liability of Jonah Klimack 
# for any damages, losses and/or causes of 
# action exceed the total amount paid by the 
# user for this software.		
#####################################################
# DO NOT MODIFY ANYTHING IN THIS FILE
#####################################################


require "header.php";
require "submenu.php";

$campaign = mysql_fetch_row(mysql_query("select * from adtrackz_campaigns where ID='$cID'"));

?>


<table width="100%">
<tr>
	<td>
		<p class="small" align="left">Campaigns > <?=$campaign[2]?> > Add Sales</p>
	</td>
	<td>
		<?load_submenu($cID,$campaign[2])?>
	</td>
</tr>
</table>

<p class="heading">
Add Sales for <?=ucfirst($campaign[2])?>
</p>

<p>
Fill out this form to manually add a sale for this campaign.
</p>

<?

if($add_sales)
{
	//validate information
	if (strlen($description) > 100)
		alert("Description is limited to 100 characters");
	elseif (!preg_match("/\b\d+\.\d{2}\b/", $revenue))
		error("Revenue must be in 0.00 format.");
	else
	{

		$time = mktime (0,0,0,$fmonth,$fday,$fyear);

		mysql_query("insert into adtrackz_sales values('','$cID','$sID','$time','$revenue','$userID','$name','$description')");		
		echo mysql_error();
		alert("The sale has been added.");

		unset($subcampaign, $fyear, $fmonth, $fday, $revenue, $userID, $name, $description);
	}
}

if ($revenue)
	$revenue = number_format($revenue, 2);
?>

<form action="dstats-sales-add.php" method="post">
<input type="hidden" name=cID value=<?=$cID?>>
<br><br>


<table width="500" border="0" cellspacing="0" cellpadding="5" align="center" bgcolor="white"  bordercolor="white">
<tr>
	<td valign="top">Product ID</td>
	<td valign="top" width="250">
		<input type="text" size="5" maxlength=15 name="userID" value="<?=$userID?>"> 		
	</td>
</tr>
<tr>
	<td>&nbsp;</td>
	<td><span class=small>
	Enter your product ID.</span>
	</td>
</tr>
<tr>
	<td valign="top">Date</td>
	<td valign="top">
	<select name="fmonth">
<?
//set the month
if (!$fmonth)
	$now_month = date("n");
else
	$now_month = $fmonth;
$months = array(1 => 'Jan', 'Feb', 'Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec');
$i=1;
foreach ($months as $month)
{
	if ($now_month == $i)
		echo "<option value=\"$i\" selected>$month</option>";	
	else
		echo "<option value=\"$i\">$month</option>";
	$i++;
}
?>
	</select>
	<select name="fday">
<?
//select this day
if (!$fday)
{
	$now_day = date("j");
	$days_in_month = date ("t");
	for ($i=1;$i<=$days_in_month;$i++)
	{
		if ($now_day == $i)
			echo "<option value=\"$i\" selected>$i</option>";	
		else
			echo "<option value=\"$i\">$i</option>";
	}
}
else
{
	$now_day = $fday;
	//need to get this month
	$days_in_month = date ("t", strtotime("$fday $months[$fmonth] $fyear"));
	for ($i=1;$i<=$days_in_month;$i++)
	{
		if ($now_day == $i)
			echo "<option value=\"$i\" selected>$i</option>";	
		else
			echo "<option value=\"$i\">$i</option>";
	}
}
?>
	</select>
	<select name="fyear">
<?
//select this year
if (!$fyear)
	$now_year = date("Y");
else
	$now_year = $fyear;
for ($i=2004;$i<=2014;$i++)
{
	if ($now_year == $i)
		echo "<option value=\"$i\" selected>$i</option>";	
	else
		echo "<option value=\"$i\">$i</option>";
}
?>
	</select>
	</td>
</tr>
<tr>
	<td>&nbsp;</td>
	<td><span class=small>
	The date of the sale.</span>
	</td>
</tr>
<tr>
	<td valign="top">Subcampaign</td>
	<td valign="top">
	<select name="sID">
	<?
		if (!$sID)
			echo "<option value=\"\" selected>None</option>";
		else
			echo "<option value=\"\">None</option>";	

		//get all the subcampaigns, display them, sorted
		$allsubs = mysql_query("select * from adtrackz_subcampaigns where campaignID='$cID' order by adcode asc");	
		while ($allsub = mysql_fetch_row($allsubs))
		{
			if ($sID == $allsub[0])
				echo "<option value=\"$allsub[0]\" selected>$allsub[2]</option>";
			else
				echo "<option value=\"$allsub[0]\">$allsub[2]</option>";
		}
	?>
	</select>
	</td>
</tr>
<tr>
	<td>&nbsp;</td>
	<td><span class=small>
	Fill this out if you want this sale to be recorded under a subcampaign.</span>
	</td>
</tr>
<tr>
	<td valign="top">Revenue</td>
	<td valign="top">
		<input type="text" size="6" maxlength="10" name="revenue" value="0.00"> 		
	</td>
</tr>
<tr>
	<td>&nbsp;</td>
	<td><span class=small>
	How much you charge for your product</span>
	</td>
</tr>
<tr>
	<td valign="top">Name</td>
	<td valign="top">
		<input type="text" size="12" maxlength="20" name="name" value="<?=$name?>"> 		
	</td>
</tr>
<tr>
	<td>&nbsp;</td>
	<td><span class=small>
	The name of your product.</span>
	</td>
</tr>
</tr>
	<td valign="top">Description</td>
	<td valign="top">
		<textarea name="description" rows=3 cols=15><?=$description?></textarea> 		
	</td>
</tr>
<tr>
	<td>&nbsp;</td>
	<td><span class=small>
	Describe your product.</span>
	</td>
</tr>
</table>
<br><br>
<center>
<input type=submit name=add_sales value="Add Sale"  >
</center>
</form>
<br>


<?
require "footer.php";

?>